#
#OPTIMIZATION=-O $(EXTRA_OPTIMIZATION)
#DEBUGGING=-g $(EXTRA_DEBUGGING)
-# add -DDEBUG_MEM to turn on memory allocation logging
GBCFLAGS=$(EXTRA_CFLAGS) $(DEBUGGING) $(BUILD_CPP) @ZLIB_CPP@ @QT_INC_OPT@$(QT_INC) \
$(OPTIMIZATION) -DHAVE_CONFIG_H -DNEW_STRINGS
LDFLAGS=$(EXTRA_LDFLAGS) @LDFLAGS@
# Declaring a target PHONY whose names matches a subdirectory can be
# particularly important, e.g. gui.
.PHONY: all clean tag more-clean check torture \
-install install-debug leaktest \
+install install-debug \
dep doc \
release-sourcecheck release-tarball release-rpm \
cross-configure \
# Nerdy release stuff that needs to work only on Linux.
-leaktest:
- make EXTRA_CFLAGS=-DDEBUG_MEM
- tools/cleardebug
- ./testo
- tools/memdebug | grep -v '^command line:'
-
dep:
make clean && make -j8 EXTRA_CFLAGS="-isystem /sw/include @QT_SYSINC_OPT@ $(QT_INC) -MMD" && cat $(sort $(DEPFILES)) > /tmp/dep && rm $(DEPFILES)
echo 'internal_styles.cc: mkstyle.sh $$(srcdir)/style/*.style' >> /tmp/dep
vec->next = cet_cs_vec_root;
cet_cs_vec_root = vec;
cet_cs_vec_ct++;
-#ifdef DEBUG_MEM
- cet_check_cs(vec);
-#endif
}
}
csv_stringtrim(const char* string, const char* enclosure, int strip_max)
{
static const char* p1 = nullptr;
- char* tmp = xxstrdup(string,file,line);
+ char* tmp = xstrdup(string);
size_t elen;
int stripped = 0;
/* function prototypes */
char*
-#ifndef DEBUG_MEM
csv_stringtrim(const char* string, const char* enclosure, int strip_max);
-#else
-CSV_STRINGTRIM(const char* string, const char* enclosure, int strip_max, DEBUG_PARAMS);
-#define csv_stringtrim( s, e,m ) CSV_STRINGTRIM( s, e, m, __FILE__, __LINE__)
-#endif
QString csv_stringtrim(const QString& source, const QString& enclosure);
char*
}
char*
-#ifndef DEBUG_MEM
csv_stringclean(const char* string, const char* chararray);
-#else
-CSV_STRINGCLEAN(const char* string, const char* chararray,DEBUG_PARAMS);
-#define csv_stringclean(s,c) CSV_STRINGCLEAN(s,c,__FILE__,__LINE__)
-#endif
QString csv_stringclean(const QString& string, const QString& chararray);
void
typedef void (*ff_writeposn)(Waypoint*);
typedef Waypoint* (*ff_readposn)(posn_status*);
-#ifndef DEBUG_MEM
char* get_option(const char* iarglist, const char* argname);
-#else
-#define DEBUG_PARAMS const char *file, const int line
-char* GET_OPTION(const char* iarglist, const char* argname, DEBUG_PARAMS);
-#define get_option(iarglist, argname) GET_OPTION(iarglist, argname, __FILE__, __LINE__)
-#endif
void xcsv_setup_internal_style(const char* style_buf);
void xcsv_read_internal_style(const char* style_buf);
} mkshort_handle_imp;
typedef mkshort_handle_imp* short_handle;
-#ifndef DEBUG_MEM
char* mkshort(short_handle, const char*);
QString mkshort(short_handle, const QString&);
short_handle mkshort_new_handle(void);
-#else
-char* MKSHORT(short_handle, const char*, DEBUG_PARAMS);
-short_handle MKSHORT_NEW_HANDLE(DEBUG_PARAMS);
-#define mkshort( a, b) MKSHORT(a,b,__FILE__, __LINE__)
-#define mkshort_new_handle() MKSHORT_NEW_HANDLE(__FILE__,__LINE__)
-#endif
QString mkshort_from_wpt(short_handle h, const Waypoint* wpt);
void mkshort_del_handle(short_handle* h);
void setshort_length(short_handle, int n);
const char* name_option(long type);
void printposn(const double c, int is_lat);
-#ifndef DEBUG_MEM
void* xcalloc(size_t nmemb, size_t size);
void* xmalloc(size_t size);
void* xrealloc(void* p, size_t s);
char* xstrdup(const QString& s);
char* xstrndup(const char* str, size_t sz);
char* xstrappend(char* src, const char* newd);
-#define xxcalloc(nmemb, size, file, line) xcalloc(nmemb, size)
-#define xxmalloc(size, file, line) xmalloc(size)
-#define xxrealloc(p, s, file, line) xrealloc(p,s)
-#define xxfree(mem, file, line) xfree(mem)
-#define xxstrdup(s, file, line) xstrdup(s)
char* xstrdup(const char* s);
-#define xxstrappend(src, addon, file, line) xstrappend(src, addon)
-#else /* DEBUG_MEM */
-void* XCALLOC(size_t nmemb, size_t size, DEBUG_PARAMS);
-void* XMALLOC(size_t size, DEBUG_PARAMS);
-void* XREALLOC(void* p, size_t s, DEBUG_PARAMS);
-void XFREE(void* mem, DEBUG_PARAMS);
-char* XSTRDUP(const char* s, DEBUG_PARAMS);
-char* XSTRNDUP(const char* src, size_t size, DEBUG_PARAMS);
-char* XSTRAPPEND(char* src, const char* addon, DEBUG_PARAMS);
-void debug_mem_open();
-void debug_mem_output(char* format, ...);
-void debug_mem_close();
-#define xcalloc(nmemb, size) XCALLOC(nmemb, size, __FILE__, __LINE__)
-#define xmalloc(size) XMALLOC(size, __FILE__, __LINE__)
-#define xrealloc(p, s) XREALLOC(p,s,__FILE__,__LINE__)
-#define xfree(mem) XFREE(mem, __FILE__, __LINE__)
-#define xstrdup(s) XSTRDUP(s, __FILE__, __LINE__)
-#define xstrndup(s, z) XSTRNDUP(s, z, __FILE__, __LINE__)
-#define xstrappend(src,addon) XSTRAPPEND(src, addon, __FILE__, __LINE__)
-#define xxcalloc XCALLOC
-#define xxmalloc XMALLOC
-#define xxrealloc XREALLOC
-#define xxfree XFREE
-#define xxstrdup XSTRDUP
-#define xxstrappend XSTRAPPEND
-#endif /* DEBUG_MEM */
FILE* xfopen(const char* fname, const char* type, const char* errtxt);
file->fileopen(file, mode);
-#ifdef DEBUG_MEM
- file->buffsz = 1;
-#else
file->buffsz = 256;
-#endif
file->buff = (char*) xmalloc(file->buffsz);
return file;
typedef int (*gbfungetc_cb)(const int c, gbfile* self);
typedef struct gbfile_s {
-#ifdef DEBUG_MEM
- void* dummy; /* ZERO pointer for stdio oop's */
-#endif
union {
FILE* std;
unsigned char* mem;
gpsbabel_now = time(nullptr); /* gpsbabel startup-time */
gpsbabel_time = current_time().toTime_t(); /* same like gpsbabel_now, but freezed to zero during testo */
-#ifdef DEBUG_MEM
- debug_mem_open();
- debug_mem_output("command line: ");
- for (int i = 1; i < qargs.size(); i++) {
- debug_mem_output("%s ", qPrintable(qargs.at(i)));
- }
- debug_mem_output("\n");
-#endif
-
if (gpsbabel_time != 0) { /* within testo ? */
global_opts.inifile = inifile_init(QString(), MYNAME);
}
exit_filter_vecs();
inifile_done(global_opts.inifile);
-#ifdef DEBUG_MEM
- debug_mem_close();
-#endif
exit(0);
}
}
short_handle
-#ifdef DEBUG_MEM
-MKSHORT_NEW_HANDLE(DEBUG_PARAMS)
-#else
mkshort_new_handle()
-#endif
{
- mkshort_handle_imp* h = (mkshort_handle_imp*) xxcalloc(sizeof *h, 1, file, line);
+ mkshort_handle_imp* h = (mkshort_handle_imp*) xcalloc(sizeof *h, 1);
for (int i = 0; i < PRIME; i++) {
QUEUE_INIT(&h->namelist[i]);
}
char*
-#ifdef DEBUG_MEM
-MKSHORT(short_handle h, const char* istring, DEBUG_PARAMS)
-#else
mkshort(short_handle h, const char* istring)
-#endif
{
char* ostring;
char* tstring;
if (hdl->is_utf8) {
ostring = cet_utf8_strdup(istring); /* clean UTF-8 string */
} else {
- ostring = xxstrdup(istring, file, line);
+ ostring = xstrdup(istring);
}
/*
if ((strlen(ostring) > hdl->target_len + 4) &&
(strncmp(ostring, "The ", 4) == 0 ||
strncmp(ostring, "the ", 4) == 0)) {
- char* nstring = xxstrdup(ostring + 4, file, line);
+ char* nstring = xstrdup(ostring + 4);
xfree(ostring);
ostring = nstring;
}
/*
* Eliminate Whitespace
*/
- tstring = xxstrdup(ostring, file, line);
+ tstring = xstrdup(ostring);
l = strlen(tstring);
cp = ostring;
for (i=0; i<l; i++) {
/*
* Eliminate chars on the blacklist.
*/
- tstring = xxstrdup(ostring, file, line);
+ tstring = xstrdup(ostring);
l = strlen(tstring);
cp = ostring;
for (i=0; i<l; i++) {
+++ /dev/null
-#!/bin/sh
-
-rm /tmp/gpsbabel.debug
-touch /tmp/gpsbabel.debug
-
+++ /dev/null
-#!/usr/bin/perl
-
-sub alloc {
- my $addr = shift;
- my $file = shift;
- my $line = shift;
-
- if ( $arena{$addr} ) {
- ($ofile,$oline) = @{$arena{$addr}};
- print( "duplicate allocation $addr at $file $line\n allocated at $ofile $oline\n" );
- }
- if ( $freed{$addr} ) {
- delete $freed{$addr};
- }
- $arena{$addr} = [$file,$line];
-}
-
-sub free {
- my $addr = shift;
- my $file = shift;
- my $line = shift;
-
- if ( $arena{$addr} ) {
- $freed{$addr} = [$arena{$addr}->[0], $arena{$addr}->[1], $file, $line];
- delete $arena{$addr};
- }
- else {
- if ($freed{$addr}) {
- ($afile,$aline,$ffile,$fline) = @{$freed{$addr}};
- print( "double free $addr at $file $line\n allocated at $afile $aline\n last freed at $ffile $fline\n" );
- }
- else {
- print( "freeing unallocated $addr at $file $line\n" );
- }
- }
-}
-
-sub unfreed {
- for $addr (keys %arena) {
- ($file,$line)=@{$arena{$addr}};
- print( "unfreed $addr allocated at $file $line\n" );
- }
- undef %arena;
- undef %freed;
-}
-
-open(FILE, "</tmp/gpsbabel.debug");
-
-while (<FILE>) {
- chomp;
- @args = split(', ',$_);
- if ($args[0] eq 'malloc') {
- &alloc($args[1], $args[3], $args[4]);
- }
- if ($args[0] eq 'calloc') {
- &alloc($args[1], $args[4], $args[5]);
- }
- if ($args[0] eq 'strdup') {
- &alloc($args[1], $args[3], $args[4]);
- }
- if ($args[0] eq 'realloc') {
- &free($args[2], $args[4], $args[5]);
- &alloc($args[1], $args[4], $args[5]);
- }
- if ($args[0] eq 'free') {
- &free($args[1], $args[2], $args[3]);
- }
- if ($args[0] =~ m/^command/) {
- &unfreed;
- print "$args[0]\n";
- }
-}
-&unfreed;
-close(FILE);
#endif
#endif
-#ifdef DEBUG_MEM
-#define DEBUG_FILENAME "/tmp/gpsbabel.debug"
-
-static FILE* debug_mem_file = NULL;
-void
-debug_mem_open()
-{
- debug_mem_file = xfopen(DEBUG_FILENAME, "a", "debug");
-}
-
-void
-debug_mem_output(char* format, ...)
-{
- va_list args;
- va_start(args, format);
- if (debug_mem_file) {
- vfprintf(debug_mem_file, format, args);
- fflush(debug_mem_file);
- }
- va_end(args);
-}
-
-void
-debug_mem_close()
-{
- if (debug_mem_file) {
- fclose(debug_mem_file);
- }
- debug_mem_file = NULL;
-}
-#endif
-
void*
-#ifdef DEBUG_MEM
-XMALLOC(size_t size, DEBUG_PARAMS)
-#else
xmalloc(size_t size)
-#endif
{
void* obj = malloc(size);
-#ifdef DEBUG_MEM
- debug_mem_output("malloc, %x, %d, %s, %d\n",
- obj, size, file, line);
-#endif
if (!obj) {
fatal("gpsbabel: Unable to allocate %ld bytes of memory.\n", (unsigned long) size);
}
}
void*
-#ifdef DEBUG_MEM
-XCALLOC(size_t nmemb, size_t size, DEBUG_PARAMS)
-#else
xcalloc(size_t nmemb, size_t size)
-#endif
{
void* obj = calloc(nmemb, size);
-#ifdef DEBUG_MEM
- debug_mem_output("calloc, %x, %d, %d, %s, %d\n",
- obj, nmemb, size, file, line);
-#endif
if (!obj) {
fatal("gpsbabel: Unable to allocate %ld units of %ld bytes of memory.\n", (unsigned long) nmemb, (unsigned long) size);
}
void
-#ifdef DEBUG_MEM
-XFREE(const void* mem, DEBUG_PARAMS)
-#else
xfree(const void* mem)
-#endif
{
free(const_cast<void*>(mem));
-#ifdef DEBUG_MEM
- debug_mem_output("free, %x, %s, %d\n",
- mem, file, line);
-#endif
}
char*
-#ifdef DEBUG_MEM
-XSTRDUP(const char* s, DEBUG_PARAMS)
-#else
xstrdup(const char* s)
-#endif
{
char* o = s ? strdup(s) : strdup("");
-#ifdef DEBUG_MEM
- debug_mem_output("strdup, %x, %x, %s, %d\n",
- o, s, file, line);
-#endif
if (!o) {
fatal("gpsbabel: Unable to allocate %ld bytes of memory.\n", (unsigned long) strlen(s));
* Duplicate at most sz bytes in str.
*/
char*
-#ifdef DEBUG_MEM
-XSTRNDUP(const char* str, size_t sz, DEBUG_PARAMS)
-#else
xstrndup(const char* str, size_t sz)
-#endif
{
size_t newlen = 0;
const char* cin = str;
}
void*
-#ifdef DEBUG_MEM
-XREALLOC(void* p, size_t s, DEBUG_PARAMS)
-#else
xrealloc(void* p, size_t s)
-#endif
{
char* o = (char*) realloc(p, s);
-#ifdef DEBUG_MEM
- if (p != NULL) {
- debug_mem_output("realloc, %x, %x, %x, %s, %d\n", o, p, s, file, line);
- } else {
- debug_mem_output("malloc, %x, %d, %s, %d\n", o, s, file, line);
- }
-#endif
if (!o) {
fatal("gpsbabel: Unable to realloc %ld bytes of memory.\n", (unsigned long) s);
* For an allocated string, realloc it and append 's'
*/
char*
-#ifdef DEBUG_MEM
-XSTRAPPEND(char* src, const char* newd, DEBUG_PARAMS)
-#else
xstrappend(char* src, const char* newd)
-#endif
{
if (!src) {
- return xxstrdup(newd, file, line);
+ return xstrdup(newd);
}
if (!newd) {
- return xxstrdup(src, file, line);
+ return xstrdup(src);
}
size_t newsz = strlen(src) + strlen(newd) + 1;
- src = (char*) xxrealloc(src, newsz, file, line);
+ src = (char*) xrealloc(src, newsz);
strcat(src, newd);
return src;
{
/* From http://perfec.to/vsnprintf/pasprintf.c */
/* size of first buffer malloc; start small to exercise grow routines */
-#ifdef DEBUG_MEM
-# define FIRSTSIZE 64
-#else
# define FIRSTSIZE 1
-#endif
char* buf = nullptr;
char* newbuf;
size_t nextsize = 0;
* Modelled approximately after getenv.
*/
char*
-#ifdef DEBUG_MEM
-GET_OPTION(const char* iarglist, const char* argname, DEBUG_PARAMS)
-#else
get_option(const char* iarglist, const char* argname)
-#endif
{
const size_t arglen = strlen(argname);
char* rval = nullptr;
* this data.
*/
if (rval) {
- rval = xxstrdup(rval,file, line);
+ rval = xstrdup(rval);
}
xfree(arglist);
return rval;